package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.DepartmentOrderBean;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/13.
 */
public class PerformListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<DepartmentOrderBean> datas;
    private RecyclerView recyclerview;
    private LayoutInflater mInflater;

    private ResultSelectedListener listener;

    public PerformListAdapter(Context mContext, List<DepartmentOrderBean> datas,
                              RecyclerView recyclerview, ResultSelectedListener listener) {
        this.mContext = mContext;
        this.datas = datas;
        this.recyclerview = recyclerview;
        this.listener = listener;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<DepartmentOrderBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clearData() {
        datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        // TODO Auto-generated method stub
        return datas.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        // TODO Auto-generated method stub


        Holder mHolder = (Holder) holder;
        mHolder.nameTV.setText(datas.get(position).getOrderName());
        mHolder.nameTV.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                listener.onSelected("click", datas.get(position));

            }

        });


    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View v = mInflater.inflate(R.layout.item_performlist_layout, null);
        RecyclerView.ViewHolder holer = new Holder(v);

        return holer;
    }

    @Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    /*
     * Holder
     */
    public class Holder extends RecyclerView.ViewHolder {

        private TextView nameTV;

        public Holder(View view) {
            super(view);
            nameTV = (TextView) view.findViewById(R.id.performlist_item_tv_name);

        }
    }

    public interface ResultSelectedListener {
        void onSelected(String type, DepartmentOrderBean info);
    }


}
